-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
removeUnusedImports - JDK15 TextBlocks - Fails when running jdk11 #1589
removeUnusedImports - JDK15 TextBlocks - Fails when running jdk11 #1589
Conversation
in |
The initial fix was relying on https://github.com/diffplug/spotless/pull/687/files#diff-282881b9b1bb0861937748f383b30476cf1134c56a5a33a450a2caa6ac4efabeR220 which seems to have moved elsewhere in main branch. |
@nedtwigg Could the issue be rooted in the runtime JDK used to execute spotless? In my case, I run a JDK11 and here I'm processing a JDK17 file |
This proposes an alternative removeUnusedImports based on javaParser (which can handle jdk17 syntax, even with a jdk11 runtime). (In my case, I run spotless over JDK11 as AWS Lambda is not yet JDK17 friendly aws/aws-lambda-base-images#29). |
Looks great! Part of me thinks we should just replace the GJF implementation with this one. And another part of me thinks we should do The synthesis is to use JavaParser by default since it should have the exact same behavior but resilient to more JDK versions. And then allow users to specify Author's choice! |
In the meantime, the author added this as a Cleanthat mutator. Hence, it would also be available as a cleanthat mutator. We may also make it available through some dedicated Glue to Cleanthat, very similarly to GJF (hence, no duplicated code between Cleanthat and Spotless). Pro GJF :
Pro Javaparser :
Part of the code is inspired from Revelc (https://github.com/revelc/impsort-maven-plugin/blob/main/src/test/java/net/revelc/code/impsort/ImpSortTest.java) but simpler as it does only removing unused imports (which Revelc also implemented imports ordering, while Spotless has a solid implementation I did not plan to challenge for this round). Need more time to :
|
I'd be happy to rely on whatever works best for
IMO our current import sorter works but has ossified such that we can't really change anything about it ever again. It underspecified some things around grouping and static imports, and now we can't fix or improve these issues without breaking the formatting of people who are "relying on the bugs". So if this PR someday becomes the foundation of a new import cleaner that can deal with groups, static imports, etc. that sounds great. That could be a Spotless DSL, or it could just be a cleanthat option that users can activate, whatever is easy. My sticking point is always that people solve the problems they themselves have, and that Spotless helps to keep them solved instead of needing to revisit the issue over and over. For people who have already adopted our existing import formatters, I don't want them to have to think about this ever again. For people who are coming to Spotless for the first time or starting new projects, I think it would be great to have a more comprehensive import cleaning solution. It might be worth thinking about an import cleaning solution which could be used across Java/Scala/Kotlin, etc. but mostly I think users don't care about that. |
Ok. I'm totally in-line. I'll release soon a cleanthat version with this, and update the PR accordingly. Regarding imports sorting, I personally do not lack anything in spotless. I came to Spotless from Revelc plugins, and some options (I do not use) may be missing in Spotless. My main discomfort is about the default configuration in Spotless (which is something, while I (personally) look for Eclipse defaults.). Also, I encountered some issues (the infamous 'Why are my files not import-sorted ?'), hence digged into Spotless import-srting implementation. I fully agree on your synthesis, and improving import-sorting is definitely a lower-value item. (I'm on this issue only because a Cleanthat user encountered this textBlock issue). |
Here is an iteration. I'm not fan of:
|
--
BarreraVIP Kamis, 02 Maret 2023, 02:31AM +08:00 dari Benoit Lacelle ***@***.*** :
…Here is an iteration.
I'm not fan of:
static final String GJF = "google-java-format";
static final String CLEANTHAT = "cleanthat-javaparser-unnecessaryimport";
—
Reply to this email directly, view it on GitHub , or unsubscribe .
You are receiving this because you are subscribed to this thread. Message ID: @ github . com>
|
I leave the default to GJF. Javaparser still encounter an issue with annotated packages (which are quite rare, but at least one known issue). People will be free to switch, and we may switch to cleanthat at any moment. |
It nows handles annotated packages. |
@nedtwigg This is a good first version. One limitation:
It would fails with something like:
Other potential limitations: |
Note for myself: I could try workaround the javaParser limitations. test. case for sealed added in the PR: it appears :
|
[...]
Forget this, too much code for today. |
9dcead6
to
7ad63c9
Compare
@nedtwigg This is ready-for-merging |
Published in |
This MR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [flow-bin](https://github.com/flowtype/flow-bin) ([changelog](https://github.com/facebook/flow/blob/master/Changelog.md)) | devDependencies | minor | [`^0.206.0` -> `^0.214.0`](https://renovatebot.com/diffs/npm/flow-bin/0.206.0/0.214.0) | | [org.liquibase.ext:liquibase-hibernate5](https://github.com/liquibase/liquibase-hibernate/wiki) ([source](https://github.com/liquibase/liquibase-hibernate)) | build | minor | `4.21.1` -> `4.22.0` | | [org.liquibase:liquibase-maven-plugin](http://www.liquibase.org/liquibase-maven-plugin) ([source](https://github.com/liquibase/liquibase)) | build | minor | `4.21.1` -> `4.23.0` | | [com.vladsch.flexmark:flexmark-all](https://github.com/vsch/flexmark-java) | compile | patch | `0.64.4` -> `0.64.8` | | [com.diffplug.spotless:spotless-maven-plugin](https://github.com/diffplug/spotless) | build | minor | `2.36.0` -> `2.38.0` | --- ### Release Notes <details> <summary>flowtype/flow-bin</summary> ### [`v0.214.0`](flow/flow-bin@a8d35e6...ca11e28) [Compare Source](flow/flow-bin@a8d35e6...ca11e28) ### [`v0.213.1`](flow/flow-bin@656b64a...a8d35e6) [Compare Source](flow/flow-bin@656b64a...a8d35e6) ### [`v0.213.0`](flow/flow-bin@733e908...656b64a) [Compare Source](flow/flow-bin@733e908...656b64a) ### [`v0.212.0`](flow/flow-bin@d057186...733e908) [Compare Source](flow/flow-bin@d057186...733e908) ### [`v0.211.1`](flow/flow-bin@669f2d7...d057186) [Compare Source](flow/flow-bin@669f2d7...d057186) ### [`v0.211.0`](flow/flow-bin@c0f5f12...669f2d7) [Compare Source](flow/flow-bin@c0f5f12...669f2d7) ### [`v0.210.2`](flow/flow-bin@6dbf435...c0f5f12) [Compare Source](flow/flow-bin@6dbf435...c0f5f12) ### [`v0.210.1`](flow/flow-bin@572b4ff...6dbf435) [Compare Source](flow/flow-bin@572b4ff...6dbf435) ### [`v0.210.0`](flow/flow-bin@026a117...572b4ff) [Compare Source](flow/flow-bin@026a117...572b4ff) ### [`v0.209.0`](flow/flow-bin@b1689a0...026a117) [Compare Source](flow/flow-bin@b1689a0...026a117) ### [`v0.208.1`](flow/flow-bin@1e8564c...b1689a0) [Compare Source](flow/flow-bin@1e8564c...b1689a0) ### [`v0.208.0`](flow/flow-bin@97db57b...1e8564c) [Compare Source](flow/flow-bin@97db57b...1e8564c) ### [`v0.207.0`](flow/flow-bin@7bf1c0e...97db57b) [Compare Source](flow/flow-bin@7bf1c0e...97db57b) </details> <details> <summary>liquibase/liquibase-hibernate</summary> ### [`v4.22.0`](https://github.com/liquibase/liquibase-hibernate/releases/tag/v4.22.0) [Compare Source](liquibase/liquibase-hibernate@v4.21.1...v4.22.0) Support for Liquibase 4.22.0. #### What's Changed - Fix diff changelog is removing unique constraint since 4.21.0 (hibernate6 + postgresql) by [@​filipelautert](https://github.com/filipelautert) in liquibase/liquibase-hibernate#480 - add Support for Hibernate EnversSettings revision_field_name and revision_type_field_name by [@​lorenzbaier](https://github.com/lorenzbaier) in liquibase/liquibase-hibernate#488 - Bump spring.version from 6.0.8 to 6.0.9 by [@​dependabot](https://github.com/dependabot) in liquibase/liquibase-hibernate#490 #### New Contributors - [@​lorenzbaier](https://github.com/lorenzbaier) made their first contribution in liquibase/liquibase-hibernate#488 **Full Changelog**: liquibase/liquibase-hibernate@v4.21.0...v4.22.0 </details> <details> <summary>liquibase/liquibase</summary> ### [`v4.23.0`](https://github.com/liquibase/liquibase/blob/HEAD/changelog.txt#Liquibase-4230-is-a-major-release) [Compare Source](liquibase/liquibase@v4.22.0...v4.23.0) ### [`v4.22.0`](https://github.com/liquibase/liquibase/blob/HEAD/changelog.txt#Liquibase-v4220-is-a-major-release) [Compare Source](liquibase/liquibase@v4.21.1...v4.22.0) </details> <details> <summary>vsch/flexmark-java</summary> ### [`v0.64.6`](vsch/flexmark-java@0.64.4...0.64.6) [Compare Source](vsch/flexmark-java@0.64.4...0.64.6) </details> <details> <summary>diffplug/spotless</summary> ### [`v2.38.0`](https://github.com/diffplug/spotless/blob/HEAD/CHANGES.md#​2380---2023-04-06) ##### Added - Support configuration of mirrors for P2 repositories in `EquoBasedStepBuilder` ([#​1629](diffplug/spotless#1629)). - The `style` option in Palantir Java Format ([#​1654](diffplug/spotless#1654)). - Added formatter for Gherkin feature files ([#​1649](diffplug/spotless#1649)). ##### Changes - **POTENTIALLY BREAKING** Converted `googleJavaFormat` to a compile-only dependency and drop support for versions < `1.8`. ([#​1630](diffplug/spotless#1630)) - Bump default `cleanthat` version to latest `2.6` -> `2.13`. ([#​1589](diffplug/spotless#1589) and [#​1661](diffplug/spotless#1661)) - Bump default `diktat` version `1.2.4.2` -> `1.2.5`. ([#​1631](diffplug/spotless#1631)) - Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#​1302](diffplug/spotless#1302)) - Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#​1630](diffplug/spotless#1630)) - Bump default `scalafmt` version `3.7.1` -> `3.7.3`. ([#​1584](diffplug/spotless#1584)) - Bump default Eclipse formatters for the 2023-03 release. ([#​1662](diffplug/spotless#1662)) - JDT and GrEclipse `4.26` -> `4.27` - Improve GrEclipse error reporting. ([#​1660](diffplug/spotless#1660)) - CDT `11.0` -> `11.1` ### [`v2.37.0`](https://github.com/diffplug/spotless/blob/HEAD/CHANGES.md#​2370---2023-03-13) ##### Added - You can now put the filename into a license header template with `$FILE`. ([#​1605](diffplug/spotless#1605) fixes [#​1147](diffplug/spotless#1147)) ##### Changes - We are now opting in to Gradle's new stable configuration cache. ([#​1591](diffplug/spotless#1591)) - Adopt [Equo Solstice OSGi and p2 shim](https://github.com/equodev/equo-ide/tree/main/solstice) to update all Eclipse-based plugins. ([#​1524](diffplug/spotless#1524)) - Eclipse JDT now supports `4.9` through `4.26`. Also we now recommend dropping the last `.0`, e.g. `4.26` instead of `4.26.0`, you'll get warnings to help you switch. - Eclipse Groovy now supports `4.18` through `4.26`. Also we now recommend dropping the last `.0`, e.g. `4.26` instead of `4.26.0`, you'll get warnings to help you switch. - Eclipse CDT now supports `10.6` through `11.0`. - Eclipse WTP is still WIP at [#​1622](diffplug/spotless#1622). </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox. 👻 **Immortal**: This MR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yNC4wIiwidXBkYXRlZEluVmVyIjoiMzQuMjQuMCJ9-->
New occurences of #681
For now, just a reproduction case